import  pymysql
try:
    connect=pymysql.connect(host="127.0.0.1",
                          user="root",
                          password="root",
                          db="spider",
                          charset="utf8",
                        cursorclass=pymysql.cursors.DictCursor)
    cursor=connect.cursor()
    sql="select * from teacherinfo"
    cursor.execute(sql)
    print(cursor.fetchall())
except Exception as err:
    connect .rollback()
    print(err)
finally:
    cursor.close()
    connect.close()